﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CRM.Database.Model.Customers>" %>

<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>


<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdContracts";
                                        settings.KeyFieldName = "IdContract";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Contracts", Action = "CustomerContractsPartialEdit",  customerId = Model.IdCustomer  };
                                        settings.SettingsPager.PageSize = 20;

                                        settings.Columns.Add(column =>
                                                                 {
                                                                     column.Caption = Resourses.LegalEntityName;
                                                                     column.FieldName = "IdAgreementElement";

                                                                     column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                                                     var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                                                     if (comboBoxProperties != null)
                                                                     {

                                                                         comboBoxProperties.DataSource = Model.AgreementsElements;
                                                                         comboBoxProperties.TextField = "LegalEntityName";
                                                                         comboBoxProperties.ValueField = "IdAgreementElement";
                                                                         comboBoxProperties.ValueType = typeof(int);
                                                                     }
                                                                 });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ContractType;
                                            column.FieldName = "IdContractType";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new ContractsTypesCollection();
                                                comboBoxProperties.DataSource = col.ContractsTypesList;
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdContractsType";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ContractNumber;
                                            column.FieldName = "ContractNumber";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ContractCreationDate;
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                            column.FieldName = "CreationDate";


                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ValidTill;
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                            column.FieldName = "ValidTill";


                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ContractProfineSignDate;
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                            column.FieldName = "SigningDate";


                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ContractCustomerSignDate;
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                            column.FieldName = "CustomerSigningDate";


                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.GettingSignedCopyDate;
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                            column.FieldName = "GettingSignedCopyDate";


                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.FirstCopyHolder;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            column.FieldName = "Id1stCopyHolder";

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new CopyHoldersCollection();
                                                comboBoxProperties.DataSource = col.CopyHoldersList;
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "Id";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }


                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.SecondCopyHolder;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            column.FieldName = "Id2ndCopyHolder";

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new CopyHoldersCollection();
                                                comboBoxProperties.DataSource = col.CopyHoldersList;
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "Id";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }

                                        });



                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.ContractStatuse;
                                            column.FieldName = "IdContractStatus";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new ContractsStatusesCollection();
                                                comboBoxProperties.DataSource = col.ContractsStatusesList;
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdContractsStatus";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            
                                            column.Caption = Resourses.ContractLink;
                                            column.FieldName = "ContractLink";
                                           
                                            column.ColumnType =MVCxGridViewColumnType.HyperLink;
                                            HyperLinkProperties properties = column.PropertiesEdit as HyperLinkProperties;
                                          

                                            properties.NavigateUrlFormatString = "{0}";
                                            properties.Text = "Ссылка";
                                        });

                                        settings.Columns.Add(column =>
                                        { 
                                            
                                            column.Caption = Resourses.ContractScanLink;
                                            column.FieldName = "ScanLink";
                                            
                                            
                                            column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                            HyperLinkProperties properties = column.PropertiesEdit as HyperLinkProperties;


                                            properties.NavigateUrlFormatString = "{0}";
                                            properties.Text = "Ссылка";
                                            
                                            
                                            column.SetEditItemTemplateContent(c =>
                                                                                  {

                                                                                      var value =  c.Grid.GetRowValues(c.VisibleIndex, c.Grid.KeyFieldName);
                                                                                      if (value !=null)
                                                                                      {
                                                                                          ViewData["contractId"] = value;
                                                                                          Html.RenderPartial("ContractScanAttachementPartial");
                                                                                      }
                                                                                  });
                                        });


                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Comments;
                                            column.ColumnType = MVCxGridViewColumnType.Memo;
                                            column.FieldName = "Comments";
                                        });


                                       

                                       

                                        
                                        //Добавление редактирования
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Contracts", Action = "CustomerContractsPartialUpdate", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Contracts", Action = "CustomerContractsPartialAdd", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Contracts", Action = "CustomerContractsPartialDelete", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        //settings.Width = Unit.Percentage(100);
                                    }).Bind(Model.Contracts).GetHtml();
                                    
                                    
                                    %>

